package org.bizming.web.action;

import java.io.IOException;
import java.util.List;

import org.bizming.base.BaseErrCode;
import org.bizming.base.BaseException;
import org.bizming.medicine.model.help.MedicineStatus;
import org.bizming.medicine.service.MedicineStatusService;
import org.bizming.web.util.WebUtil;

public class MedicineStatusAction {

	private MedicineStatusService statusService;

	private MedicineStatus ms;

	/** 修改数据 */
	public String addOrUpdate() {
		int errCode = BaseErrCode.SUCCESS;

		try {
			if (null != ms && null == ms.getId()) {
				statusService.add(ms);
			} else {
				statusService.update(ms);
			}

			WebUtil.getResponse().sendRedirect(
					WebUtil.getRequest().getContextPath() + "/medicineStatus!selectList.action");
			return null;
		} catch (BaseException e) {
			errCode = e.getErrCode();
		} catch (Exception e) {
			e.printStackTrace();
			errCode = BaseErrCode.SERVER_ERROR;
		}
		WebUtil.getRequest().setAttribute("code", errCode);
		WebUtil.getRequest().setAttribute("o", ms);
		return "addOrUpdate_exception";
	}

	/** 查看数据 */
	public String view() {
		MedicineStatus t = null;
		if (null != ms && null != ms.getId()) {
			t = statusService.get(ms.getId());
		}
		WebUtil.getRequest().setAttribute("o", t);
		return "view";
	}

	/**
	 * 删除数据
	 * 
	 * @throws IOException
	 */
	public String remove() throws IOException {

		if (null != ms && null != ms.getId()) {
			statusService.remove(ms.getId());
		}

		WebUtil.getResponse().sendRedirect(
				WebUtil.getRequest().getContextPath() + "/medicineStatus!selectList.action");
		return null;
	}

	/** 获取数据 */
	public String selectList() {

		List<MedicineStatus> list = statusService.selectList();
		WebUtil.getRequest().setAttribute("list", list);

		return "selectList";
	}

	// ===============================================

	public MedicineStatusService getStatusService() {
		return statusService;
	}

	public void setStatusService(MedicineStatusService statusService) {
		this.statusService = statusService;
	}

	public MedicineStatus getMs() {
		return ms;
	}

	public void setMs(MedicineStatus ms) {
		this.ms = ms;
	}

}
